<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增友情链接')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-info-add">
            <input type="hidden" name="keyCode" value="outLink"/>
            <input type="hidden" name="description" value="友情链接" />
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">链接标题：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">链接地址：</label>
                <div class="col-sm-8">
                    <textarea name="link" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">排序：</label>
                <div class="col-sm-8">
                    <input name="idx" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">图片</label>
                <input type="hidden" name="imgUrl" id="imgUrl"/>
                <div class="col-sm-8">
                    <input id="singleFile" name="file" type="file">
                </div>
            </div>


        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "info/info"
        $("#form-info-add").validate({
            rules: {
                name: "required",
                idx: "required"
            },
            messages: {
                name: icon + "必填项",
                keywords: icon + "必填项"
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                 $.operate.save(prefix + "/add", $('#form-info-add').serialize());
            }
        }


        $("#singleFile").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            var rsp = data.response;
            log.info("return url：" + rsp.url)
            log.info("reutrn fileName：" + rsp.fileName)
            log.info("reutrn newFileName：" + rsp.newFileName)
            log.info("return originalFilename：" + rsp.originalFilename)

            $('#imgUrl').val(rsp.fileName)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
    </script>
</body>
</html>